import UcRequest, { UcResponse } from './ucRequest'

/**
 * 账户注册
 */
export default class UserRegisterRequest extends UcRequest
{
    module = 'user'
    action = 'register'
    httpMethod = 'post'
    constructor(username,password,email,regIp='0.0.0.0'){
        super()
        this.params = {
            username:username,
            password:password,
            email:email,
            regip:regIp
        }
    }
    
}

export class UserRegisterResponse extends UcResponse
{
    constructor(respRaw){
        super(respRaw);
        let uId = parseInt(respRaw);
        uId = isNaN(uId)?0:uId;
        if(uId > 0){
            this.userId = uId;
            this.errCode = 1;
            this.errMsg = '用户注册成功';
            this.isSuccess = true;
        }else{
            this.userId = 0;
            this.errCode = uId;
            this.isSuccess = false;
            switch(this.errCode){
                case -1:
                    this.errMsg = '用户名不合法';
                    break;
                case -2:
                    this.errMsg = '包含不允许注册的词语';
                    break;
                case -3:
                    this.errMsg = '用户名已经存在'
                    break;
                case -4:
                    this.errMsg = 'Email 格式有误';
                    break;
                case -5:
                    this.errMsg = 'Email 不允许注册';
                    break;
                case -6:
                    this.errMsg = '该 Email 已经被注册';
                    break;
                default:
                    if(respRaw.length > 0){
                        this.errMsg = respRaw; // 如果响应的正文是文本信息，则直接作为错误消息
                    }else{
                        this.errMsg = '未知的错误！';
                    }
            }
        }
        
    }
}